﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Farmacia.Entities;
using Farmacia.BussinessLogic;
using Farmacia.BussinessLogic.Almacen.Laborat;
using Farmacia.BussinessLogic.Almacen.GrupoFarma;
using Farmacia.BussinessLogic.Almacen.PrincActivo;
using Microsoft.Practices.Unity;

namespace Farmacia.net.Almacen
{
    public partial class frmRegistrarProducto : BasePage<frmRegistrarProducto>
    {
        [Dependency]
        public iProductoBL ProductoBL { get; set; }

        [Dependency]
        public iProveedorBL ProveedorBL { get; set; }
        [Dependency]
        public iLaboratorioBL laboratorioBL { get; set; }
        [Dependency]
        public IPrincipioActivoBL princActBL { get; set; }
        [Dependency]
        public IGrupoFarmBL grupFarmaBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var opc = Request.QueryString["acc"];

            if (opc != string.Empty)
            {
                if (opc == "ver")
                {
                    FormView1.ChangeMode(FormViewMode.ReadOnly);

                }
                if (opc == "editar")
                {
                    FormView1.ChangeMode(FormViewMode.Edit);

                }
                if (opc == "nuevo")
                {
                    FormView1.ChangeMode(FormViewMode.Insert);
                }
                if (opc == "eliminar")
                {
                    ObjectDataSource1.DataObjectTypeName = "";
                    ObjectDataSource1.Delete();
                    Response.Redirect("frmBuscarProducto");

                }

            }
        }

        protected void OdsRegistrar_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = ProductoBL;
        }

        protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = ProductoBL;
        }

        protected void ObjectDataSource1_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("frmBuscarProducto.aspx");
        }

        protected void ObjectDataSource1_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("frmBuscarProducto.aspx");
        }

        protected void ObjectDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            Response.Redirect("frmBuscarProducto.aspx");
        }

        protected void odsProveedor_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = ProveedorBL;
        }

        protected void odsPrincActivo_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = princActBL;
        }

        protected void odsGrupFarma_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = grupFarmaBL;
        }

        protected void odsLaboratorio_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = laboratorioBL;
        }

        protected void odsProvInsert_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = princActBL;
        }

        protected void odsLabInsert_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = laboratorioBL;
        }

        protected void odsGrupFarma_ObjectCreating1(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = grupFarmaBL;
        }

        protected void odsPrinActInsert_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = princActBL;
        }
        
    }
}